package edu.uic.ids517.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


import edu.uic.ids517.model.DatabaseAccessBean;
import edu.uic.ids517.model.DropTableBean;

public class DropTableServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 

		System.out.println("DropTableServlet");
		String nextUrl = "/dbAccess.jsp";	
		HttpSession session = request.getSession();


		/***   DB Access Bean  ****/
		DatabaseAccessBean dbase = (DatabaseAccessBean) session.getAttribute("dbaseBean");
		DropTableBean dropTable = (DropTableBean) session.getAttribute("dropTableBean");

		dropTable.setTableName(request.getParameter("tableName"));


		dbase.setDropTableBean(dropTable);
		int result = dbase.executeDropSQL();
		if(result == 0){
			System.out.println("SUCCESS: TABLE DROPED" + request.getParameter("tableName"));
			request.setAttribute("message", "Table dropped!!");
		}
		else{
			request.setAttribute("message", "Error!!");
		}
		RequestDispatcher dispatcher = request.getRequestDispatcher(nextUrl); 
		dispatcher.forward(request, response);


	}
}
